/**
 * Created by 15c on 2018/2/24.
 */
//我的钱包
app.controller('mywallet', function ($scope, $http) {
    //页面控制js
    $scope.buyNow = function () {
        var show = document.getElementsByClassName('alert-all')[0];
        show.style.display = 'block';


    };
    $scope.buyNo = function () {
        var show = document.getElementsByClassName('alert-all')[0];
        show.style.display = 'none';


    };
    var token = localStorage.getItem('token');
    if (!token) {
        $.toast("请先登录");
        location.href = '#user-login';
        return;
    } else {
        $http({
            method: 'get',
            url: app.netPath + '/users/details/show',
            headers: {'Authorization': token}
        }).then(function (res) {
            console.log(res.data);
            $scope.userBalance = res.data.data.userBalance.toFixed(2);
        });


        $scope.addUserBalance = function () {
            if ($scope.balance == null || $scope.balance == '') {
                $.toast("金额不可为空");
            } else {
                $http({
                    method: 'get',
                    url: app.netPath + '/users/details/addBalance',
                    headers: {'Authorization': token},
                    params: {money: $scope.balance}
                }).then(function (res) {
                    console.log(res.data);

                    if (!res.data.error) {
                        $.toast("充值成功");
                        location.href = '#mywallet';
                    } else {
                        $.toast(res.data.msg);
                    }
                });
            }
        }

    }


});